<template>
    <div>
        <el-table :data="store.getters['seck/getSeck']" border style="width: 100%">
            <el-table-column prop="title" label="活动名称" width="180">
            </el-table-column>
            <el-table-column label="状态" width="180">
                <template v-slot="item">
                    <div>
                        <el-tag v-if="item.row.status == 1" type="success" plain size="large">启用</el-tag>
                        <el-tag v-else type="danger" plain size="large">禁用</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="操作">
                <template v-slot="item">
                    <div>
                        <el-button type="primary" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script lang="ts" setup>
import { seckdelete } from '@/request/api';
import { useStore } from 'vuex';
import { defineEmits } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus'
let emit = defineEmits(['edit'])
let store = useStore()

let edit = (id:number) => {
    emit("edit", id)
}
let del = (id:any) => {

        ElMessageBox.confirm(
            '删除后不可恢复，是否确认删除？',
            {
                confirmButtonText: '删除',
                cancelButtonText: '取消',
                type: 'warning',
            }
        )
            .then(() => {
                seckdelete({ id }).then((res:any) => {
                    if (res.code == 200) {
                        get()
                        ElMessage({
                            type: 'success',
                            message: '删除成功！',
                        })
                    }
                })
            })
            .catch(() => {
                ElMessage({
                    type: 'info',
                    message: '取消删除！',
                })
            })
    }
let get = () =>{
    store.dispatch("seck/getSeckListActions")
}
get()

</script>